﻿
Namespace LightSwitchApplication

    Public Class Pregnancy

        Private Sub EDCComputed_Compute(ByRef result As Date)
            ' Set result to the desired field value
            Select Case calctype
                Case 1 'LNMP
                    result = If(lnmpdate.HasValue _
                      , DateAdd(DateInterval.Day, 6, (DateAdd(DateInterval.Month, 9, CDate(lnmpdate)))) _
                      , Nothing)
                Case 2 'SCAN
                    If daysatscan Is Nothing Then
                        daysatscan = 0
                    End If
                    result = If(scandate.HasValue _
                      , DateAdd(DateInterval.Day, 6, (DateAdd(DateInterval.Month, 9, DateAdd(DateInterval.Day, CInt(daysatscan) * -1, CDate(scandate))))) _
                      , Nothing)
                Case Else 'Others
                    result = If(edcdate.HasValue _
                      , CDate(edcdate) _
                      , Nothing)
            End Select

        End Sub

        Private Sub WeeksNow_Compute(ByRef result As Integer)
            ' Set result to the desired field value
            Select Case calctype
                Case 1 'LNMP
                    result = If(lnmpdate.HasValue _
                      , DateDiff(DateInterval.Weekday, CDate(lnmpdate), Now) _
                      , Nothing)
                Case 2 'SCAN
                    If daysatscan Is Nothing Then
                        daysatscan = 0
                    End If
                    result = If(scandate.HasValue _
                      , DateDiff(DateInterval.Weekday, DateAdd(DateInterval.Day, CInt(daysatscan) * -1, CDate(scandate)), Now) _
                      , Nothing)
                Case Else 'Others
                    result = If(edcdate.HasValue _
                                , DateDiff(DateInterval.Weekday, DateAdd(DateInterval.Day, -280, CDate(edcdate)), Now) _
                                , Nothing)
            End Select
        End Sub
    End Class

End Namespace
